/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package at.ac.big.tuwien.ewa.picasa;

import com.google.gdata.client.photos.PicasawebService;
import com.google.gdata.data.photos.AlbumFeed;
import com.google.gdata.data.photos.PhotoEntry;
import com.google.gdata.util.ServiceException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import org.apache.log4j.Logger;

/**
 *
 * @author robert
 */
@ManagedBean(name="picasa")
@ViewScoped
public class Picasa implements PicasaConnector{
    
    private final static Logger LOG = Logger.getLogger(Picasa.class.getName());
    PicasawebService myService = new PicasawebService("UTVienna-WebEng4-1");
    public List<Avatar> avatarList = new ArrayList<Avatar>();
    
    public Picasa() throws MalformedURLException, IOException, ServiceException{
        URL feedUrl = new URL("https://picasaweb.google.com/data/feed/base/user/111420671758947023853/albumid/5708523142385535377");
        AlbumFeed feed = myService.getFeed(feedUrl, AlbumFeed.class);

        for(PhotoEntry photo : feed.getPhotoEntries()) {
            Avatar a = new Avatar();
            a.setDescription(photo.getTitle().getPlainText());
            //a.setUrl("bla");
            a.setUrl(photo.getMediaContents().get(0).getUrl());
            avatarList.add(a);
            LOG.debug("Avatar "+ photo.getTitle().getPlainText() + " erstellt und in Liste eingetragen");
            
        }
    }
    
    @Override
    public List<Avatar> getPhotoURLs() throws MalformedURLException, IOException, ServiceException {

        return avatarList;
    }
    
}
